<%@page import="com.edu.bean.Book"%>
<%@page import="java.util.List"%>
<%@page import="com.edu.service.impl.BookServiceImpl"%>
<%@page import="com.edu.service.BookService"%>
<%@page import="com.edu.bean.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String style = "book1.css";
	Cookie[] cookies = request.getCookies();
	if(cookies!=null){
		for(Cookie c : cookies){
			if("style".equals(c.getName())){
				style = c.getValue();
			}
		}
	}
	
	if(request.getAttribute("books") == null){
		BookService bs = new BookServiceImpl();
		List<Book> books = bs.getAllBook();
		request.setAttribute("books", books);
	}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="/demo/css/<%=style %>" />
</head>
<body>
	<!-- 引入登录的判断，没登录跳回 登录页面 -->
	<%@ include file="isLogin.jsp" %>
	<c:if test="${loginUser.sex=='男'}">
		欢迎${loginUser.realName}先生
	</c:if>
	<c:if test="${loginUser.sex=='女'}">
		欢迎${loginUser.realName}女士
	</c:if>
	<% 
	
	%>
	<a href="addBook.jsp">添加书本</a>
	<a href="changeStyle.do?style=1">样式一</a>
	<a href="changeStyle.do?style=2">样式二</a> 
	<a href="updatePwd.jsp">修改密码</a>
	<a href="loginOut.do">退出登录</a> <br>
	<form action="searchBook.do" method="GET">
		书名:<input type="text" name="bookName">
			<input type="submit" value="查找">
	</form>
	<table border="1" width="700">
		<tr>
			<th>
				序号
			</th>
			<th>
				书本id
			</th>
			<th>
				书本名
			</th>
			<th>
				作者
			</th>
			<th>
				类型
			</th>
			<th>
				库存
			</th>
			<th>
				价格
			</th>
			<th>
				操作
			</th>
		</tr>
		<c:forEach items="${books}" var="book" varStatus="stat">
			<c:if test="${stat.count%2==0}">
				<tr class="color2">
			</c:if>
			<c:if test="${stat.count%2!=0}">
				<tr class="color1">
			</c:if>
				<td>
					${stat.count}
				</td>
				<td>
					${book.bookId}
				</td>
				<td>
					${book.bookName}
				</td>
				<td>
					${book.bookWriter}
				</td>
				<td>
					${book.bookType}
				</td>
				<td>
					${book.bookNum}
				</td>
				<td>
					${book.bookPrice}
				</td>
				<td>
					<a href="deleteBook.do?bookId=${book.bookId}">删除<a>
					<a href="updateBook.jsp?bookId=${book.bookId}" >修改<a>
				</td>
			</tr>
		</c:forEach>
	</table>
</body>

</html>